Vowpal Wabbit
VectorZipper
- Python
- Scala
- .NET
from synapse.ml.vw import *
df = spark.createDataFrame([
("action1_f", "action2_f"),
("action1_f", "action2_f"),
("action1_f", "action2_f"),
("action1_f", "action2_f")
], ["action1", "action2"])
actionOneFeaturizer = (VowpalWabbitFeaturizer()
.setInputCols(["action1"])
.setOutputCol("sequence_one"))
actionTwoFeaturizer = (VowpalWabbitFeaturizer()
.setInputCols(["action2"])
.setOutputCol("sequence_two"))
seqDF = actionTwoFeaturizer.transform(actionOneFeaturizer.transform(df))
vectorZipper = (VectorZipper()
.setInputCols(["sequence_one", "sequence_two"])
.setOutputCol("out"))
vectorZipper.transform(seqDF).show()
import com.microsoft.azure.synapse.ml.vw._
val df = (Seq(
("action1_f", "action2_f"),
("action1_f", "action2_f"),
("action1_f", "action2_f"),
("action1_f", "action2_f")
).toDF("action1", "action2"))
val actionOneFeaturizer = (new VowpalWabbitFeaturizer()
.setInputCols(Array("action1"))
.setOutputCol("sequence_one"))
val actionTwoFeaturizer = (new VowpalWabbitFeaturizer()
.setInputCols(Array("action2"))
.setOutputCol("sequence_two"))
val seqDF = actionTwoFeaturizer.transform(actionOneFeaturizer.transform(df))
val vectorZipper = (new VectorZipper()
.setInputCols(Array("sequence_one", "sequence_two"))
.setOutputCol("out"))
vectorZipper.transform(seqDF).show()
using System;
using System.Collections.Generic;
using Synapse.ML.Vw;
using Microsoft.Spark.Sql;
using Microsoft.Spark.Sql.Types;
namespace SynapseMLApp
{
class Program
{
static void Main(string[] args)
{
SparkSession spark =
SparkSession
.Builder()
.AppName("Example")
.GetOrCreate();
DataFrame df = spark.CreateDataFrame(
new List<GenericRow>
{
new GenericRow(new object[] {"action1_f", "action2_f"}),
new GenericRow(new object[] {"action1_f", "action2_f"}),
new GenericRow(new object[] {"action1_f", "action2_f"}),
new GenericRow(new object[] {"action1_f", "action2_f"})
},
new StructType(new List<StructField>
{
new StructField("action1", new StringType()),
new StructField("action2", new StringType())
})
);
var actionOneFeaturizer = new VowpalWabbitFeaturizer()
.SetInputCols(new string[]{"action1"})
.SetOutputCol("sequence_one");
var actionTwoFeaturizer = new VowpalWabbitFeaturizer()
.SetInputCols(new string[]{"action2"})
.SetOutputCol("sequence_two");
var seqDF = actionTwoFeaturizer.Transform(actionOneFeaturizer.Transform(df));
var vectorZipper = new VectorZipper()
.SetInputCols(new string[]{"sequence_one", "sequence_two"})
.SetOutputCol("out");
vectorZipper.Transform(seqDF).Show();
spark.Stop();
}
}
}
Python API: VectorZipper | Scala API: VectorZipper | Source: VectorZipper |
VowpalWabbitClassifier
- Python
- Scala
from synapse.ml.vw import *
vw = (VowpalWabbitClassifier()
.setNumBits(10)
.setLearningRate(3.1)
.setPowerT(0)
.setLabelConversion(False))
import com.microsoft.azure.synapse.ml.vw._
val vw = (new VowpalWabbitClassifier()
.setNumBits(10)
.setLearningRate(3.1)
.setPowerT(0)
.setLabelConversion(false))
Python API: VowpalWabbitClassifier | Scala API: VowpalWabbitClassifier | Source: VowpalWabbitClassifier |
VowpalWabbitFeaturizer
- Python
- Scala
from synapse.ml.vw import *
featurizer = (VowpalWabbitFeaturizer()
.setStringSplitInputCols(["in"])
.setPreserveOrderNumBits(2)
.setNumBits(18)
.setPrefixStringsWithColumnName(False)
.setOutputCol("features"))
import com.microsoft.azure.synapse.ml.vw._
val featurizer = (new VowpalWabbitFeaturizer()
.setStringSplitInputCols(Array("in"))
.setPreserveOrderNumBits(2)
.setNumBits(18)
.setPrefixStringsWithColumnName(false)
.setOutputCol("features"))
Python API: VowpalWabbitFeaturizer | Scala API: VowpalWabbitFeaturizer | Source: VowpalWabbitFeaturizer |
VowpalWabbitInteractions
- Python
- Scala
from synapse.ml.vw import *
interactions = (VowpalWabbitInteractions()
.setInputCols(["v1"])
.setOutputCol("out"))
import com.microsoft.azure.synapse.ml.vw._
import org.apache.spark.ml.linalg._
case class Data(v1: Vector, v2: Vector, v3: Vector)
val df = spark.createDataFrame(Seq(Data(
Vectors.dense(Array(1.0, 2.0, 3.0)),
Vectors.sparse(8, Array(5), Array(4.0)),
Vectors.sparse(11, Array(8, 9), Array(7.0, 8.0))
)))
val interactions = (new VowpalWabbitInteractions()
.setInputCols(Array("v1"))
.setOutputCol("out"))
interactions.transform(df).show()
Python API: VowpalWabbitInteractions | Scala API: VowpalWabbitInteractions | Source: VowpalWabbitInteractions |